﻿using System;
using System.Collections.Generic;
using System.Text;

namespace IceDog.DNL.CSharp.Algorithm
{
    public class AlgoSimple
    {
        public int RemoveDuplicates(int[] nums)
        {
            //方法：双指针法
            //指针1，慢指针，此下标以及之前的元素不会重复
            var point1 = 0;
            var length = nums.Length;
            //如果数组长度为0，返回0；
            if (length == 0) { return 0; }
            //指针2:快指针，用于遍历数组
            for (var point2 = 1; point2 < length; point2 += 1)
            {
                var point2Value = nums[point2];
                //如果当前值和慢指针所在的值不同
                //慢指针的值加1，把当前值赋值给现在慢指针所在位置
                if (nums[point1] != point2Value)
                {
                    point1 += 1;
                    nums[point1] = point2Value;
                }
            }
            //数组下标+1即为当前数组长度
            return point1 + 1;
        }

        public string ReverseString(string s)
        {
            //长度为0或1的字符串直接返回即可
            if (s.Length == 0 || s.Length == 1) { return s; }
            var t = "";
            var length = s.Length;
            for (var i = length - 1; i >= 0; i -= 1)
            {
                t += s[i];
            }
            return t;
        }
    }
}
